package drongo.desktop.menu
{
	import drongo.desktop.undo.UndoSystem;
	import drongo.desktop.utils.FileUtil;
	
	import flash.display.NativeMenu;
	import flash.display.Stage;
	import flash.events.Event;

	public class DGMenuBar
	{
		private var menu:NativeMenu;
		private var menuEventHandler:Function;
		/**
		 * 系统菜单栏 
		 * @param stage
		 * @param xmlPath
		 * @param menuEventHandler 回调函数function(e:Event):void
		 * 
		 */		
		public function DGMenuBar(stage:Stage,xmlPath:String,menuEventHandler:Function,undo:UndoSystem=null)
		{
			var xml:XML=XML(FileUtil.openAsString(xmlPath));
			if(xml==null){
				throw new Error(xmlPath+" Menu配置出错!");
			}
			menu=MenuHelper.createByXML(xml,null,undo);
			menu.addEventListener(Event.SELECT,onSelect);
			stage.nativeWindow.menu=menu;
			this.menuEventHandler=menuEventHandler;
		}
		private function onSelect(e:Event):void{
			if(menuEventHandler!=null){
				menuEventHandler(e);
			}
		}
	}
}